.class Lnet/oauth/signature/pem/DerParser;
.super Ljava/lang/Object;
.source "DerParser.java"


# static fields
.field public static final ANY:I = 0x0

.field public static final APPLICATION:I = 0x40

.field public static final BIT_STRING:I = 0x3

.field public static final BMP_STRING:I = 0x1e

.field public static final BOOLEAN:I = 0x1

.field public static final CONSTRUCTED:I = 0x20

.field public static final CONTEXT:I = 0x80

.field public static final ENUMERATED:I = 0xa

.field public static final GENERALIZED_TIME:I = 0x18

.field public static final GENERAL_STRING:I = 0x1b

.field public static final GRAPHIC_STRING:I = 0x19

.field public static final IA5_STRING:I = 0x16

.field public static final INTEGER:I = 0x2

.field public static final ISO646_STRING:I = 0x1a

.field public static final NULL:I = 0x5

.field public static final NUMERIC_STRING:I = 0x12

.field public static final OBJECT_IDENTIFIER:I = 0x6

.field public static final OCTET_STRING:I = 0x4

.field public static final PRINTABLE_STRING:I = 0x13

.field public static final PRIVATE:I = 0xc0

.field public static final REAL:I = 0x9

.field public static final RELATIVE_OID:I = 0xd

.field public static final SEQUENCE:I = 0x10

.field public static final SET:I = 0x11

.field public static final T61_STRING:I = 0x14

.field public static final UNIVERSAL:I = 0x0

.field public static final UNIVERSAL_STRING:I = 0x1c

.field public static final UTC_TIME:I = 0x17

.field public static final UTF8_STRING:I = 0xc

.field public static final VIDEOTEX_STRING:I = 0x15


# instance fields
.field protected in:Ljava/io/InputStream;


# direct methods
.method public constructor <init>(Ljava/io/InputStream;)V
    .locals 0
    .parameter "in"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 88
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 89
    iput-object p1, p0, Lnet/oauth/signature/pem/DerParser;->in:Ljava/io/InputStream;

    .line 90
    return-void
.end method

.method public constructor <init>([B)V
    .locals 1
    .parameter "bytes"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 100
    new-instance v0, Ljava/io/ByteArrayInputStream;

    invoke-direct {v0, p1}, Ljava/io/ByteArrayInputStream;-><init>([B)V

    invoke-direct {p0, v0}, Lnet/oauth/signature/pem/DerParser;-><init>(Ljava/io/InputStream;)V

    .line 101
    return-void
.end method

.method private getLength()I
    .locals 7
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 147
    iget-object v4, p0, Lnet/oauth/signature/pem/DerParser;->in:Ljava/io/InputStream;

    invoke-virtual {v4}, Ljava/io/InputStream;->read()I

    move-result v1

    .line 148
    .local v1, i:I
    const/4 v4, -0x1

    if-ne v1, v4, :cond_0

    .line 149
    new-instance v4, Ljava/io/IOException;

    const-string v5, "Invalid DER: length missing"

    invoke-direct {v4, v5}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V

    throw v4

    .line 152
    :cond_0
    and-int/lit8 v4, v1, -0x80

    if-nez v4, :cond_1

    .line 167
    .end local v1           #i:I
    :goto_0
    return v1

    .line 155
    .restart local v1       #i:I
    :cond_1
    and-int/lit8 v3, v1, 0x7f

    .line 158
    .local v3, num:I
    const/16 v4, 0xff

    if-ge v1, v4, :cond_2

    const/4 v4, 0x4

    if-le v3, v4, :cond_3

    .line 159
    :cond_2
    new-instance v4, Ljava/io/IOException;

    new-instance v5, Ljava/lang/StringBuilder;

    invoke-direct {v5}, Ljava/lang/StringBuilder;-><init>()V

    const-string v6, "Invalid DER: length field too big ("

    invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-virtual {v5, v1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v5

    const-string v6, ")"

    invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v5

    invoke-direct {v4, v5}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V

    throw v4

    .line 162
    :cond_3
    new-array v0, v3, [B

    .line 163
    .local v0, bytes:[B
    iget-object v4, p0, Lnet/oauth/signature/pem/DerParser;->in:Ljava/io/InputStream;

    invoke-virtual {v4, v0}, Ljava/io/InputStream;->read([B)I

    move-result v2

    .line 164
    .local v2, n:I
    if-ge v2, v3, :cond_4

    .line 165
    new-instance v4, Ljava/io/IOException;

    const-string v5, "Invalid DER: length too short"

    invoke-direct {v4, v5}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V

    throw v4

    .line 167
    :cond_4
    new-instance v4, Ljava/math/BigInteger;

    const/4 v5, 0x1

    invoke-direct {v4, v5, v0}, Ljava/math/BigInteger;-><init>(I[B)V

    invoke-virtual {v4}, Ljava/math/BigInteger;->intValue()I

    move-result v1

    goto :goto_0
.end method


# virtual methods
.method public read()Lnet/oauth/signature/pem/Asn1Object;
    .locals 7
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 112
    iget-object v5, p0, Lnet/oauth/signature/pem/DerParser;->in:Ljava/io/InputStream;

    invoke-virtual {v5}, Ljava/io/InputStream;->read()I

    move-result v3

    .line 114
    .local v3, tag:I
    const/4 v5, -0x1

    if-ne v3, v5, :cond_0

    .line 115
    new-instance v5, Ljava/io/IOException;

    const-string v6, "Invalid DER: stream too short, missing tag"

    invoke-direct {v5, v6}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V

    throw v5

    .line 117
    :cond_0
    invoke-direct {p0}, Lnet/oauth/signature/pem/DerParser;->getLength()I

    move-result v0

    .line 119
    .local v0, length:I
    new-array v4, v0, [B

    .line 120
    .local v4, value:[B
    iget-object v5, p0, Lnet/oauth/signature/pem/DerParser;->in:Ljava/io/InputStream;

    invoke-virtual {v5, v4}, Ljava/io/InputStream;->read([B)I

    move-result v1

    .line 121
    .local v1, n:I
    if-ge v1, v0, :cond_1

    .line 122
    new-instance v5, Ljava/io/IOException;

    const-string v6, "Invalid DER: stream too short, missing value"

    invoke-direct {v5, v6}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V

    throw v5

    .line 124
    :cond_1
    new-instance v2, Lnet/oauth/signature/pem/Asn1Object;

    invoke-direct {v2, v3, v0, v4}, Lnet/oauth/signature/pem/Asn1Object;-><init>(II[B)V

    .line 126
    .local v2, o:Lnet/oauth/signature/pem/Asn1Object;
    return-object v2
.end method
